local Musha_Spellpower =
	Class(
	function(self, inst)
		self.inst = inst

		if TheWorld.ismastersim then
			self.classified = inst.player_classified
		elseif self.classified == nil and inst.player_classified ~= nil then
			self:AttachClassified(inst.player_classified)
		end
	end
)

function Musha_Spellpower:OnRemoveFromEntity()
	if self.classified ~= nil then
		if TheWorld.ismastersim then
			self.classified = nil
		else
			self.inst:RemoveEventCallback("onremove", self.ondetachclassified, self.classified)
			self:DetachClassified()
		end
	end
end

Musha_Spellpower.OnRemoveEntity = Musha_Spellpower.OnRemoveFromEntity

function Musha_Spellpower:AttachClassified(classified)
	self.classified = classified
	self.ondetachclassified = function()
		self:DetachClassified()
	end
	self.inst:ListenForEvent("onremove", self.ondetachclassified, classified)
end

function Musha_Spellpower:DetachClassified()
	self.classified = nil
	self.ondetachclassified = nil
end

--------------------------------------------------------------------------

function Musha_Spellpower:SetCurrent(current)
	if self.classified ~= nil then
		self.classified:SetValue("currentmusha_spellpower", current)
	end
end

function Musha_Spellpower:SetMax(max)
	if self.classified ~= nil then
		self.classified:SetValue("maxmusha_spellpower", max)
	end
end

function Musha_Spellpower:Max()
	if self.inst.components.musha_spellpower ~= nil then
		return self.inst.components.musha_spellpower.max
	elseif self.classified ~= nil then
		return self.classified.maxmusha_spellpower:value()
	else
		return 100
	end
end

function Musha_Spellpower:GetPercent()
	if self.inst.components.musha_spellpower ~= nil then
		return self.inst.components.musha_spellpower:GetPercent()
	elseif self.classified ~= nil then
		return self.classified.currentmusha_spellpower:value() / self.classified.maxmusha_spellpower:value()
	else
		return .75
	end
end

function Musha_Spellpower:GetCurrent()
	if self.inst.components.musha_spellpower ~= nil then
		return self.inst.components.musha_spellpower.current
	elseif self.classified ~= nil then
		return self.classified.currentmusha_spellpower:value()
	else
		return 75
	end
end

return Musha_Spellpower
